Requires Scripting PRO
The HealthCategorySample class represents an individual category-based health record, such as a sleep session, menstrual flow level, or a test result. These samples are used to store discrete events or conditions over time, usually characterized by a start and end date along with a categorical value.
This class is suitable for:
| Property | Type | Description |
|---|---|---|
uuid |
string |
A unique identifier for the sample. |
categoryType |
HealthCategoryType |
The category type of the sample (e.g., sleepAnalysis, sexualActivity). |
startDate |
Date |
The start date and time of the recorded event. |
endDate |
Date |
The end date and time of the recorded event. |
value |
number |
The categorical value for the sample, from a specific HealthCategoryValue enum. |
metadata |
Record<string, any> | null |
Optional additional metadata about the sample (e.g., source, notes). |
static create(...)Creates a new HealthCategorySample instance using the specified parameters.
| Parameter | Type | Description |
|---|---|---|
type |
HealthCategoryType |
The category type this sample represents. |
startDate |
Date |
When the health event began. |
endDate |
Date |
When the health event ended. |
value |
One of the HealthCategoryValue* enums |
The specific categorical value. Must match the type. |
metadata |
Optional Record<string, any> |
Optional data such as annotations or tracking source. |
HealthCategorySample instance if the inputs are valid.null if the parameters are invalid (e.g., value/type mismatch).valueThe value field must be a valid enum value for the given category type. For example:
sleepAnalysis must use HealthCategoryValueSleepAnalysissexualActivity must use HealthCategoryValuePresencemenstrualFlow must use HealthCategoryValueSeverityovulationTestResult must use HealthCategoryValueOvulationTestResultIf the value and type do not match, the sample creation will fail and return null.
| Type | Value Enum | Use Case Example |
|---|---|---|
sleepAnalysis |
HealthCategoryValueSleepAnalysis |
Sleep tracking apps |
sexualActivity |
HealthCategoryValuePresence |
Lifestyle logging |
menstrualFlow |
HealthCategoryValueSeverity |
Menstrual health apps |
pregnancyTestResult |
HealthCategoryValuePregnancyTestResult |
Fertility tracking |
appleStandHour |
HealthCategoryValueAppleStandHour |
Stand reminder history |
environmentalAudioExposureEvent |
HealthCategoryValueEnvironmentalAudioExposureEvent |
Noise alerts tracking |